package com.sailfish.springbootdemo.service.db1;

import com.alibaba.fastjson.JSONObject;
import com.sailfish.springbootdemo.configs.UserHeaderHolder;
import com.sailfish.springbootdemo.dao.db1.PcbaDeviceParamTypeDao;
import com.sailfish.springbootdemo.dao.db1.PcbaDeviceTypeDao;
import com.sailfish.springbootdemo.dao.db1.PcbaDeviceParamDao;
import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.*;
import com.sailfish.springbootdemo.pojo.db4.Operate;
import com.sailfish.springbootdemo.service.db4.OperateService;
import com.sailfish.springbootdemo.utils.CommonUtils;
import com.sailfish.springbootdemo.utils.FileConverterUtils;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.*;
import java.util.Base64;

@Service
public class PcbaDeviceParamServiceImpl implements PcbaDeviceParamService {

    @Autowired
    private PcbaDeviceParamDao pcbaDeviceParamDao;

    @Autowired
    private PcbaDeviceTypeDao pcbaDeviceTypeDao;

    @Autowired
    private PcbaDeviceParamTypeDao pcbaDeviceParamTypeDao;

    @Qualifier("MysqlTransactionManager1")
    @Autowired
    private DataSourceTransactionManager transactionManager1;

    @Autowired
    private CommonJudgeCanDeleteService commonService;

    @Autowired
    private OperateService operateService;

    @Autowired
    private CoreAlgorithmService coreAlgorithmService;

    @Autowired
    private CommonTriggerStatusService commonTriggerStatusService;

    @Value("${personal.config.file.file-save-url}")
    private String fileSaveUrl;

    @Value("${personal.config.amazon-s3.url}")
    private String url;
    @Value("${personal.config.amazon-s3.file-bucket}")
    private String fileBucket;
    @Value("${personal.config.env}")
    private String env;

    private String operateSmallType = "设备模板管理-基线模板";

    @Override
    public List<PcbaDeviceParam> getAllPcbaDeviceParam(HttpServletRequest request, Integer pcbaDeviceTypeId, Integer pcbaDeviceParamTypeId, String searchPcbaDeviceParamName) {
        List<PcbaDeviceParam> list = pcbaDeviceParamDao.getAllPcbaDeviceParam(pcbaDeviceTypeId, pcbaDeviceParamTypeId, searchPcbaDeviceParamName);
        for (PcbaDeviceParam pcbaDeviceParam : list) {

            if (pcbaDeviceParam.getPcbaDeviceParamPicture() != null && !"".equals(pcbaDeviceParam.getPcbaDeviceParamPicture())) {
                if (env != null && env.contains("pro"))  {
                    pcbaDeviceParam.setPcbaDeviceParamPictureBase64(CommonUtils.base64Prefix() + CommonUtils.getImageBase64FromUrl(url + "/" + fileBucket + "/" + pcbaDeviceParam.getPcbaDeviceParamPicture()));
                } else {
                    if(request != null){
                        pcbaDeviceParam.setPcbaDeviceParamPictureBase64(CommonUtils.base64Prefix() + CommonUtils.getImageBase64FromUrl(CommonUtils.getApiPrefixUrl(request) + "/" + pcbaDeviceParam.getPcbaDeviceParamPicture()));
                    }
                }
            }

            PcbaDeviceParamType pcbaDeviceParamType = pcbaDeviceParamTypeDao.getPcbaDeviceParamTypeById(pcbaDeviceParam.getPcbaDeviceParamTypeId());
            pcbaDeviceParam.setPcbaDeviceParamType(pcbaDeviceParamType);
        }

        return list;
    }

    @Transactional(transactionManager = "MysqlTransactionManager1")
    @Override
    public Result analysisPcbaDeviceParamExcel(MultipartFile file) {
        try {
            if (file == null) {
                return ResultUtil.error(500, "缺少参数file", "Miss Param file", null);
            }
            List<Map<String, Object>> list = new ArrayList<>();
            // 1.得到一个输入流对象
            //FileInputStream in = FileConverterUtils.convertTo(file);
            InputStream inputStream = file.getInputStream();
            File f = FileConverterUtils.getTempFileFromInputStream(inputStream);
            // 2.将输入流对象进行解析 得到workbook对象
            //Workbook workbook = new XSSFWorkbook(in);
            Workbook workbook = WorkbookFactory.create(f);
            // 3.workbook中有几个工作簿
            int sheetNum = workbook.getNumberOfSheets();
            System.out.println("一共有" + sheetNum + "个工作簿");
            // 3.1通过workbook 创建工作簿对象
            //Sheet sheet1 = workbook.getSheetAt(0);
            //Sheet sheet2 = workbook.getSheetAt(1);
            for (int a = 0; a < 1; a++) {
                Sheet sheet = workbook.getSheetAt(a);
                int allRows = sheet.getLastRowNum() + 1;
                System.out.println("sheet" + (a + 1) + "一共有：" + allRows + "行");
                String sheetName = sheet.getSheetName();
                System.out.println("当前sheetName：" + sheetName);

                Map<String, Object> map = new HashMap<>();
                //标题行 第三行开始
                Row row = sheet.getRow(2);
                String t1 = "";
                try{
                    t1 = row.getCell(0) != null ? row.getCell(0).toString() : "";
                }catch (NullPointerException e){
                    e.printStackTrace();
                    return ResultUtil.error(500, "异常：可能模板错误", e.getMessage(), null);
                }
                String t2 = row.getCell(1) != null ? row.getCell(1).toString() : "";
                String t3 = row.getCell(2) != null ? row.getCell(2).toString() : "";
                String t4 = row.getCell(3) != null ? row.getCell(3).toString() : "";
                String t5 = row.getCell(4) != null ? row.getCell(4).toString() : "";
                String t6 = row.getCell(5) != null ? row.getCell(5).toString() : "";
                String t7 = row.getCell(6) != null ? row.getCell(6).toString() : "";
                String t8 = row.getCell(7) != null ? row.getCell(7).toString() : "";
                if (t1.contains("序号") &&
                        t2.contains("设备") &&
                        t3.contains("项目大类") &&
                        t4.contains("设备能力评估项") &&
                        t5.contains("备注") &&
                        t6.contains("设计说明") &&
                        t7.contains("是否必填") &&
                        t8.contains("文本提示内容")
                ) {
                    // 表头符合的，循环获取每行数据
                    //List<Map<String,Object>> list2 = new ArrayList<>();
                    for (int b = 3; b < allRows; b++) {
                        Map<String, Object> map2 = new HashMap<>();
                        Row rowV = sheet.getRow(b);
                        //String v1 = rowV.getCell(0) != null ? rowV.getCell(0).toString() : "";
                        String v2 = rowV.getCell(1) != null ? rowV.getCell(1).toString() : "";
                        String v3 = rowV.getCell(2) != null ? rowV.getCell(2).toString() : "";
                        String v4 = rowV.getCell(3) != null ? rowV.getCell(3).toString() : "";
                        String v5 = rowV.getCell(4) != null ? rowV.getCell(4).toString() : "";
                        String v6 = rowV.getCell(5) != null ? rowV.getCell(5).toString() : "";
                        String v7 = rowV.getCell(6) != null ? rowV.getCell(6).toString() : "";
                        String v8 = rowV.getCell(7) != null ? rowV.getCell(7).toString() : "";
                        // 第一列 不管
                        // 第二列 设备 存在合并单元格
                        // 第三列 项目大类 存在合并单元格
                        // 第四列 设备能力评估项 不能为空，需要处理特殊符号
                        // 第五列 备注 不用管
                        // 第六列 设计说明 不能为空，需要解析并处理特殊符号
                        // 第七列 是否必填 为是 则必填  否则均为非必填
                        // 第八列 文本提示内容 不用管

                        String mergedCellValue1 = "";
                        String mergedCellValue2 = "";
                        // 获取合并单元格的数量
                        int mergedRegions = sheet.getNumMergedRegions();
                        for (int i = 0; i < mergedRegions; i++) {
                            CellRangeAddress cellRangeAddress = sheet.getMergedRegion(i);
                            int firstRow = cellRangeAddress.getFirstRow();
                            int lastRow = cellRangeAddress.getLastRow();
                            int firstCol = cellRangeAddress.getFirstColumn();
                            int lastCol = cellRangeAddress.getLastColumn();
                            if (b >= firstRow && b <= lastRow && firstCol == 1 && lastCol == 1) {
                                Cell cell = sheet.getRow(firstRow).getCell(1);
                                mergedCellValue1 = cell.getStringCellValue();
                                break;
                            }
                        }
                        for (int i = 0; i < mergedRegions; i++) {
                            CellRangeAddress cellRangeAddress = sheet.getMergedRegion(i);
                            int firstRow = cellRangeAddress.getFirstRow();
                            int lastRow = cellRangeAddress.getLastRow();
                            int firstCol = cellRangeAddress.getFirstColumn();
                            int lastCol = cellRangeAddress.getLastColumn();
                            if (b >= firstRow && b <= lastRow && firstCol == 2 && lastCol == 2) {
                                Cell cell = sheet.getRow(firstRow).getCell(2);
                                mergedCellValue2 = cell.getStringCellValue();
                                break;
                            }
                        }
                        //System.out.println("mergedCellValue1===" + mergedCellValue1);
                        //System.out.println("mergedCellValue2===" + mergedCellValue2);
                        map2.put("pcbaDeviceTypeName", (v2 != null && !"".equals(v2)) ? v2 : mergedCellValue1);
                        map2.put("pcbaDeviceParamType", (v3 != null && !"".equals(v3)) ? v3 : mergedCellValue2);
                        map2.put("pcbaDeviceParamName", v4);
                        map2.put("notes", v5);
                        map2.put("pcbaDeviceParamFillType", v6);
                        map2.put("isRequired", "是".equals(v7) ? 1 : 2);
                        map2.put("pcbaDeviceParamPlaceholder", v8);
                        list.add(map2);
                    }
                    //map.put("pcbaDeviceParamList", list2);
                } else {
                    return ResultUtil.error(500, "模板错误", "Error Template", null);
                }
                //list.add(map);
            }
            //return ResultUtil.success(list);
            // 得到list 然后做处理
            int importNum = 0;
            List<PcbaDeviceParam> addList = new ArrayList<>();
            String userId = UserHeaderHolder.getUserId();
            Date d = new Date();
            for (Map<String, Object> h : list) {
                String isRequired = h.get("isRequired") != null ? h.get("isRequired").toString() : "2";
                String notes = h.get("notes") != null ? h.get("notes").toString() : "";
                String pcbaDeviceParamFillType = h.get("pcbaDeviceParamFillType") != null ? h.get("pcbaDeviceParamFillType").toString() : "";
                String pcbaDeviceParamName = h.get("pcbaDeviceParamName") != null ? h.get("pcbaDeviceParamName").toString() : "";
                String pcbaDeviceParamPlaceholder = h.get("pcbaDeviceParamPlaceholder") != null ? h.get("pcbaDeviceParamPlaceholder").toString() : "";
                String pcbaDeviceParamType = h.get("pcbaDeviceParamType") != null ? h.get("pcbaDeviceParamType").toString() : "";
                String pcbaDeviceTypeName = h.get("pcbaDeviceTypeName") != null ? h.get("pcbaDeviceTypeName").toString() : "";
                // 判断设备类型
                PcbaDeviceType pcbaDevice = pcbaDeviceTypeDao.getPcbaDeviceTypeByNameCn(pcbaDeviceTypeName);
                if (pcbaDevice != null) {
                    int pcbaDeviceTypeId = pcbaDevice.getPcbaDeviceTypeId();
                    if (pcbaDeviceParamType != null && !"".equals(pcbaDeviceParamType)) {
                        // 判断能力项分类
                        PcbaDeviceParamType pcbaDeviceParamType1 = pcbaDeviceParamTypeDao.getByPcbaDeviceTypeIdAndName(pcbaDeviceTypeId, pcbaDeviceParamType);
                        if (pcbaDeviceParamType1 != null) {
                            int pcbaDeviceParamTypeId = pcbaDeviceParamType1.getPcbaDeviceParamTypeId();
                            // 判断能力项
                            PcbaDeviceParam pcbaDeviceParam = pcbaDeviceParamDao.getByNameAndPcbaDeviceParamTypeId(pcbaDeviceParamTypeId, pcbaDeviceParamName);
                            if (pcbaDeviceParam == null) {
                                if (pcbaDeviceParamFillType != null && !"".equals(pcbaDeviceParamFillType)) {
                                    // insert
                                    PcbaDeviceParam addPcbaDeviceParam = new PcbaDeviceParam();
                                    addPcbaDeviceParam.setPcbaDeviceTypeId(pcbaDeviceTypeId);
                                    addPcbaDeviceParam.setPcbaDeviceParamNameCn(pcbaDeviceParamName);
                                    addPcbaDeviceParam.setPcbaDeviceParamNameEn(pcbaDeviceParamName);
                                    addPcbaDeviceParam.setPcbaDeviceParamKey("bulk_" + System.currentTimeMillis());
                                    addPcbaDeviceParam.setCreateTime(d);
                                    addPcbaDeviceParam.setSort(100);
                                    addPcbaDeviceParam.setStatus(1);
                                    addPcbaDeviceParam.setIsRequired(Integer.parseInt(isRequired));
                                    addPcbaDeviceParam.setPcbaDeviceParamTypeId(pcbaDeviceParamTypeId);
                                    addPcbaDeviceParam.setPcbaDeviceParamPlaceholder(pcbaDeviceParamPlaceholder);
                                    addPcbaDeviceParam.setNotes(notes);
//                                    1：普通文本
//                                    2.下拉选择
//                                    3：文件上传
//                                    11：数值类型[整数]
//                                    12：数值类型[小数]
//                                    21：百分比
//                                    4：下拉多选
//                                    31：不限制 or NA or 数字
                                    int fillType = 1;
                                    String fillOptions = "";
                                    if ("普通文本".equals(pcbaDeviceParamFillType)) {
                                        fillType = 1;
                                    } else if ("整数".equals(pcbaDeviceParamFillType)) {
                                        fillType = 11;
                                    } else if ("小数".equals(pcbaDeviceParamFillType)) {
                                        fillType = 12;
                                    } else if (pcbaDeviceParamFillType.contains("下拉选择")) {
                                        fillType = 2;
                                        fillOptions = pcbaDeviceParamFillType.replace("下拉选择", "").replaceAll("（", "").replaceAll("\\(", "").replaceAll("）", "").replaceAll("\\)", "").replaceAll("，", ",");
                                    } else if (pcbaDeviceParamFillType.contains("下拉多选")) {
                                        fillType = 4;
                                        fillOptions = pcbaDeviceParamFillType.replace("下拉多选", "").replaceAll("（", "").replaceAll("\\(", "").replaceAll("）", "").replaceAll("\\)", "").replaceAll("，", ",");
                                    } else if ("百分比".equals(pcbaDeviceParamFillType)) {
                                        fillType = 21;
                                    } else if ("不限制 or NA or 数字".equals(pcbaDeviceParamFillType)) {
                                        fillType = 31;
                                    }
                                    addPcbaDeviceParam.setPcbaDeviceParamFillType(fillType);
                                    addPcbaDeviceParam.setPcbaDeviceParamOptions(fillOptions);
                                    pcbaDeviceParamDao.addPcbaDeviceParam(addPcbaDeviceParam);
                                    importNum++;
                                    addList.add(addPcbaDeviceParam);
                                }
                            }
                        }
                    }
                }
            }

            if (addList.size() > 0) {
                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 2, 1, d, null, JSONObject.toJSONString(addList)));
            }

            Map<String, Object> mm = new HashMap<>();
            mm.put("list", list);
            mm.put("importNum", importNum);
            return ResultUtil.success(mm);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result deleteById(Integer pcbaDeviceParamId) {
        PcbaDeviceParam pcbaDeviceParamById = pcbaDeviceParamDao.getPcbaDeviceParamById(pcbaDeviceParamId);
        try {
            if (pcbaDeviceParamId == null || "".equals(pcbaDeviceParamId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaDeviceParamId", "Miss Param pcbaDeviceParamId", null);
            }
            String userId = UserHeaderHolder.getUserId();
            String judgeKey = pcbaDeviceParamById.getPcbaDeviceParamKey();
            Map<String, Integer> stringIntegerMap = commonService.judgeCanDeletePcbaDeviceParam(judgeKey);
            if (stringIntegerMap.get("relatedTechParamNum") > 0 || stringIntegerMap.get("relatedRuleNum") > 0) {
                return ResultUtil.error(500,
                        "禁止删除，当前项" + stringIntegerMap.get("relatedTechParamNum") + "处应用于工艺模板，" + stringIntegerMap.get("relatedRuleNum") + "处应用于基线整线能力规则",
                        "Forbidden Delete", null);
            }
            if (pcbaDeviceParamById.getIsRelatedPcba() != null && pcbaDeviceParamById.getIsRelatedPcba() == 1) {
                return ResultUtil.error(500, "参与pcba能力匹配，禁止删除", "Forbidden Delete", null);
            }
            Integer i = pcbaDeviceParamDao.deleteById(pcbaDeviceParamId);
            if (i > 0) {
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 2, 1, new Date(), JSONObject.toJSONString(pcbaDeviceParamById), null));

                //coreAlgorithmService.cascadeChangeAllParams("1_1", pcbaDeviceParamById.getPcbaDeviceTypeId(), null);
                return ResultUtil.success(null);
            }
            return ResultUtil.error(500, "操作失败", "Operate Fail", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        } finally {
            // 删除后 pcbaDeviceParamId 查不到数据了
            //commonTriggerStatusService.changeBaseDeviceResourceStatus(pcbaDeviceParamById.getPcbaDeviceTypeId(), null);
        }
    }

    @Override
    public Boolean addPcbaDeviceParam(PcbaDeviceParam pcbaDeviceParam) {
        pcbaDeviceParam.setCreateTime(new Date());
        //coreAlgorithmService.cascadeChangeAllParams("1_1", pcbaDeviceParam.getPcbaDeviceTypeId(), null);
        return pcbaDeviceParamDao.addPcbaDeviceParam(pcbaDeviceParam) > 0;
    }

    @Override
    public Boolean updatePcbaDeviceParam(PcbaDeviceParam pcbaDeviceParam) {
        pcbaDeviceParam.setUpdateTime(new Date());
        return pcbaDeviceParamDao.updatePcbaDeviceParam(pcbaDeviceParam) > 0;
    }

    @Override
    public Result addOrUpdatePcbaDeviceParam(PcbaDeviceParam pcbaDeviceParam, String mode) {
        try {
            if (pcbaDeviceParam == null) {
                return ResultUtil.error(500, "缺少参数pcbaDeviceParam", "Miss Param pcbaDeviceParam", null);
            }
            if (mode == null || "".equals(mode)) {
                return ResultUtil.error(500, "缺少参数mode", "Miss Param mode", null);
            }
            if (!("update".equals(mode) || "add".equals(mode))) {
                return ResultUtil.error(500, "mode 参数错误", "mode Param Error", null);
            }
            String userId = UserHeaderHolder.getUserId();
            if ("update".equals(mode)) {
                if (pcbaDeviceParam.getPcbaDeviceParamId() == null || "".equals(pcbaDeviceParam.getPcbaDeviceParamId().toString())) {
                    return ResultUtil.error(500, "缺少参数pcbaDeviceParamId", "Miss Param pcbaDeviceParamId", null);
                }

                List<PcbaDeviceParam> pcbaDeviceParamList = pcbaDeviceParamDao.judgeUniquePcbaDeviceParam(pcbaDeviceParam.getPcbaDeviceTypeId(), pcbaDeviceParam.getPcbaDeviceParamTypeId(), pcbaDeviceParam.getPcbaDeviceParamId(), pcbaDeviceParam.getPcbaDeviceParamNameCn());
                if (pcbaDeviceParamList.size() > 0) {
                    return ResultUtil.error(500, "修改失败，存在相同名字", "Operate Fail", null);
                }

                // 查询原先的
                PcbaDeviceParam search = new PcbaDeviceParam();
                search.setPcbaDeviceParamId(pcbaDeviceParam.getPcbaDeviceParamId());
                PcbaDeviceParam oldPcbaDeviceParam = pcbaDeviceParamDao.getByPcbaDeviceParam(search);
                String beforeData = JSONObject.toJSONString(oldPcbaDeviceParam);
                if (updatePcbaDeviceParam(pcbaDeviceParam)) {
                    operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 1, new Date(), beforeData, JSONObject.toJSONString(pcbaDeviceParam)));
                    return ResultUtil.success(null);
                }
                return ResultUtil.error(500, "操作失败", "Operate Fail", null);
            } else {

                PcbaDeviceParam pcbaDeviceParamByName = pcbaDeviceParamDao.getPcbaDeviceParamByName(pcbaDeviceParam.getPcbaDeviceTypeId(), pcbaDeviceParam.getPcbaDeviceParamTypeId(), pcbaDeviceParam.getPcbaDeviceParamNameCn());
                if (pcbaDeviceParamByName != null) {
                    return ResultUtil.error(500, "该项已存在", "Already Exist", null);
                }

                if (addPcbaDeviceParam(pcbaDeviceParam)) {
                    operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 1, 1, new Date(), null, JSONObject.toJSONString(pcbaDeviceParam)));
                    return ResultUtil.success(null);
                }
                return ResultUtil.error(500, "操作失败", "Operate Fail", null);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        } finally {
            //commonTriggerStatusService.changeBaseDeviceResourceStatus(pcbaDeviceParam.getPcbaDeviceTypeId(), pcbaDeviceParam.getPcbaDeviceParamId());
        }
    }

    @Override
    public Result exportPcbaDeviceParamExcel() {
        try {
            String excelName = "设备基线能力参数反馈表";
            List<PcbaDeviceType> list = pcbaDeviceTypeDao.getAllPcbaDeviceType(null, 2);

            // 创建工作簿对象
            Workbook workbook = new XSSFWorkbook();
            // 创建工作表对象
            Sheet sheet = workbook.createSheet(CommonUtils.handleSheetName(excelName));
            // 创建行和单元格对象
            Row row = sheet.createRow(0);

            CellStyle bigTitleContextCellStyle = workbook.createCellStyle();
            Font bigTitleFont = workbook.createFont();
            bigTitleFont.setBold(true);
            bigTitleFont.setFontHeightInPoints((short) 20);
            bigTitleContextCellStyle.setFont(bigTitleFont);
            bigTitleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
            bigTitleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            // 第一行大标题【设备基线能力参数反馈表】
            Cell cell = row.createCell(0);
            cell.setCellValue(excelName);
            cell.setCellStyle(bigTitleContextCellStyle);
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));
            // 第二行 【注：模板内容不涉及，则填写NA】
            row = sheet.createRow(1);
            cell = row.createCell(0);
            cell.setCellValue("注：模板内容不涉及，则填写NA");
            sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7));


            CellStyle bodyContextCellStyle = workbook.createCellStyle();
            DataFormat format = workbook.createDataFormat();
            bodyContextCellStyle.setDataFormat(format.getFormat("@"));
            bodyContextCellStyle.setBorderBottom(BorderStyle.THIN);
            bodyContextCellStyle.setBorderLeft(BorderStyle.THIN);
            bodyContextCellStyle.setBorderRight(BorderStyle.THIN);
            bodyContextCellStyle.setBorderTop(BorderStyle.THIN);
            bodyContextCellStyle.setAlignment(HorizontalAlignment.LEFT);
            bodyContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

            CellStyle titleContextCellStyle = workbook.createCellStyle();
            titleContextCellStyle.setBorderBottom(BorderStyle.THIN);
            titleContextCellStyle.setBorderLeft(BorderStyle.THIN);
            titleContextCellStyle.setBorderRight(BorderStyle.THIN);
            titleContextCellStyle.setBorderTop(BorderStyle.THIN);
            titleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
            titleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            // 设置背景色为红色
            titleContextCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
            // 创建字体对象
            Font titleFont = workbook.createFont();
            // 设置字体颜色为蓝色
            titleFont.setColor(IndexedColors.WHITE.getIndex());
            titleFont.setBold(true);
            titleContextCellStyle.setFont(titleFont);
            // 设置填充类型为填充实体背景
            titleContextCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
            List<Map<String, Object>> titleList = new ArrayList<>();

            Map<String, Object> map = new HashMap<>();
            map = new HashMap<>();
            map.put("title", "序号");
            map.put("width", 2000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "设备");
            map.put("width", 6000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "项目大类");
            map.put("width", 6000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "设备能力评估项");
            map.put("width", 15000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "备注");
            map.put("width", 6000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "设计说明");
            map.put("width", 15000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "是否必填");
            map.put("width", 4000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "文本提示内容");
            map.put("width", 15000);
            titleList.add(map);
            row = sheet.createRow(2);
            for (int a = 0; a < titleList.size(); a++) {
                sheet.setColumnWidth(a, Integer.parseInt(titleList.get(a).get("width").toString()));
                sheet.setDefaultRowHeight((short) 450);
                cell = row.createCell(a);
                // 向单元格中写入数据
                cell.setCellValue(titleList.get(a).get("title").toString());
                cell.setCellStyle(titleContextCellStyle);
            }

            int index = 0; // 序号
            int beginIndex1 = 3; //用于计算合并单元格 【设备】一列，从第四行开始
            int beginIndex2 = 3; //用于计算合并单元格 【项目大类】一列，从第四行开始
            // 渲染数据
            for (int b = 0; b < list.size(); b++) {
                List<PcbaDeviceParamType> pcbaDeviceParamTypeList = pcbaDeviceParamTypeDao.getPcbaDeviceParamTypeByPcbaDeviceTypeId(list.get(b).getPcbaDeviceTypeId(), null);
                if (pcbaDeviceParamTypeList != null && pcbaDeviceParamTypeList.size() > 0) {
                    for (int c = 0; c < pcbaDeviceParamTypeList.size(); c++) {
                        List<PcbaDeviceParam> pcbaDeviceParamList = pcbaDeviceParamDao.getAllPcbaDeviceParam(null, pcbaDeviceParamTypeList.get(c).getPcbaDeviceParamTypeId(), null);
                        if (pcbaDeviceParamList != null && pcbaDeviceParamList.size() > 0) {
                            for (int d = 0; d < pcbaDeviceParamList.size(); d++) {
                                index++;
                                Row row_ = sheet.createRow(index + 2);

                                // 序号
                                Cell cell_ = row_.createCell(0);
                                cell_.setCellValue(index);
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 设备
                                cell_ = row_.createCell(1);
                                cell_.setCellValue(list.get(b).getPcbaDeviceTypeNameCn());
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 项目大类
                                cell_ = row_.createCell(2);
                                cell_.setCellValue(pcbaDeviceParamTypeList.get(c).getPcbaDeviceParamTypeName());
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 设备能力评估项
                                cell_ = row_.createCell(3);
                                cell_.setCellValue(pcbaDeviceParamList.get(d).getPcbaDeviceParamNameCn());
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 备注
                                cell_ = row_.createCell(4);
                                cell_.setCellValue(pcbaDeviceParamList.get(d).getNotes());
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 设计说明
                                /*1：普通文本
                                2.下拉选择
                                3：文件上传
                                4.下拉多选
                                11：数值类型[整数]
                                12：数值类型[小数]
                                21：百分比
                                31:不限制 or NA or 数字
                                */
                                cell_ = row_.createCell(5);
                                cell_.setCellValue(pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 1 ? "普通文本" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 2 ? "下拉选择" + "(" + pcbaDeviceParamList.get(d).getPcbaDeviceParamOptions() + ")" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 3 ? "文件上传" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 11 ? "整数" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 12 ? "小数" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 21 ? "百分比" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 4 ? "下拉多选" + "(" + pcbaDeviceParamList.get(d).getPcbaDeviceParamOptions() + ")" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 31 ? "不限制 or NA or 数字" : ""))))))));
                                cell_.setCellStyle(bodyContextCellStyle);

                                System.out.println("pcbaDeviceParamList.get(d).getIsRequired()===" + pcbaDeviceParamList.get(d).getIsRequired());
                                cell_ = row_.createCell(6);
                                cell_.setCellValue(pcbaDeviceParamList.get(d).getIsRequired() == 1 ? "是" : "否");
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 文本提示内容
                                cell_ = row_.createCell(7);
                                cell_.setCellValue(pcbaDeviceParamList.get(d).getPcbaDeviceParamPlaceholder());
                                cell_.setCellStyle(bodyContextCellStyle);
                            }
                            // 合并第三列 【项目大类】
                            System.out.println("pcbaDeviceParamList.size()=" + pcbaDeviceParamList.size());
                            if (pcbaDeviceParamList.size() > 1) {
                                if (index + 2 > beginIndex2) {
                                    sheet.addMergedRegion(new CellRangeAddress(beginIndex2, index + 2, 2, 2));
                                    beginIndex2 = index + 3;
                                }
                            } else {
                                beginIndex2 = index + 3;
                            }
                        }
                    }
                    // 合并第二列 【设备】
                    //System.out.println("beginRow===" + beginIndex1);
                    //System.out.println("lastRow===" + (index + 2));
                    //if(pcbaDeviceParamTypeList.size() > 1){
                    if (index + 2 > beginIndex1) {
                        sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index + 2, 1, 1));
                        beginIndex1 = index + 3;
                    }
                    /*}else{
                        beginIndex2 = index + 3;
                    }*/
                }
            }

            String fileName = excelName + CommonUtils.getTimestamp() + ".xlsx";
            String pathPrefix = fileSaveUrl + "exportExcels\\";
            File folder = new File(pathPrefix);
            if (!folder.isDirectory()) {
                folder.mkdirs();
            }
            String filePath = pathPrefix + fileName;
            // 导出Excel文件
            FileOutputStream outputStream = new FileOutputStream(filePath);
            workbook.write(outputStream);
            workbook.close();
            outputStream.close();

            byte[] data = null;
            InputStream in = new FileInputStream(filePath);
            data = new byte[in.available()];
            in.read(data);
            in.close();
            Base64.Encoder encoder = Base64.getEncoder();
            String base64 = encoder.encodeToString(data);

            Map<String, Object> resMap = new HashMap<>();
            resMap.put("base64", base64);
            resMap.put("fileName", fileName);
            return ResultUtil.success(resMap);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result exportPcbaDeviceParamExcelByDeviceType(Integer pcbaDeviceTypeId) {
        try {
            if (pcbaDeviceTypeId == null || "".equals(pcbaDeviceTypeId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaDeviceTypeId", "Miss Param pcbaDeviceTypeId", null);
            }
            PcbaDeviceType pcbaDeviceType = pcbaDeviceTypeDao.getById(pcbaDeviceTypeId);
            if (pcbaDeviceType != null) {
                String excelName = pcbaDeviceType.getPcbaDeviceTypeNameCn() + "-设备基线能力参数反馈表";
                // 创建工作簿对象
                Workbook workbook = new XSSFWorkbook();
                // 创建工作表对象
                Sheet sheet = workbook.createSheet(CommonUtils.handleSheetName(excelName));
                // 创建行和单元格对象
                Row row = sheet.createRow(0);

                CellStyle bigTitleContextCellStyle = workbook.createCellStyle();
                Font bigTitleFont = workbook.createFont();
                bigTitleFont.setBold(true);
                bigTitleFont.setFontHeightInPoints((short) 20);
                bigTitleContextCellStyle.setFont(bigTitleFont);
                bigTitleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
                bigTitleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

                // 第一行大标题【设备基线能力参数反馈表】
                Cell cell = row.createCell(0);
                cell.setCellValue(excelName);
                cell.setCellStyle(bigTitleContextCellStyle);
                sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
                // 第二行 【注：模板内容不涉及，则填写NA】
                row = sheet.createRow(1);
                cell = row.createCell(0);
                cell.setCellValue("注：模板内容不涉及，则填写NA");
                sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 6));


                CellStyle bodyContextCellStyle = workbook.createCellStyle();
                DataFormat format = workbook.createDataFormat();
                bodyContextCellStyle.setDataFormat(format.getFormat("@"));
                bodyContextCellStyle.setBorderBottom(BorderStyle.THIN);
                bodyContextCellStyle.setBorderLeft(BorderStyle.THIN);
                bodyContextCellStyle.setBorderRight(BorderStyle.THIN);
                bodyContextCellStyle.setBorderTop(BorderStyle.THIN);
                bodyContextCellStyle.setAlignment(HorizontalAlignment.LEFT);
                bodyContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

                CellStyle titleContextCellStyle = workbook.createCellStyle();
                titleContextCellStyle.setBorderBottom(BorderStyle.THIN);
                titleContextCellStyle.setBorderLeft(BorderStyle.THIN);
                titleContextCellStyle.setBorderRight(BorderStyle.THIN);
                titleContextCellStyle.setBorderTop(BorderStyle.THIN);
                titleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
                titleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
                // 设置背景色为红色
                titleContextCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
                // 创建字体对象
                Font titleFont = workbook.createFont();
                // 设置字体颜色为蓝色
                titleFont.setColor(IndexedColors.WHITE.getIndex());
                titleFont.setBold(true);
                titleContextCellStyle.setFont(titleFont);
                // 设置填充类型为填充实体背景
                titleContextCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                List<Map<String, Object>> titleList = new ArrayList<>();

                Map<String, Object> map = new HashMap<>();
                map = new HashMap<>();
                map.put("title", "序号");
                map.put("width", 2000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "设备");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "项目大类");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "设备能力评估项");
                map.put("width", 15000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "设备加工能力参数");
                map.put("width", 10000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "设计说明");
                map.put("width", 15000);
                titleList.add(map);
                row = sheet.createRow(2);
                for (int a = 0; a < titleList.size(); a++) {
                    sheet.setColumnWidth(a, Integer.parseInt(titleList.get(a).get("width").toString()));
                    sheet.setDefaultRowHeight((short) 450);
                    cell = row.createCell(a);
                    // 向单元格中写入数据
                    cell.setCellValue(titleList.get(a).get("title").toString());
                    cell.setCellStyle(titleContextCellStyle);
                }

                int index = 0; // 序号
                int beginIndex1 = 3; //用于计算合并单元格 【设备】一列，从第四行开始
                int beginIndex2 = 3; //用于计算合并单元格 【项目大类】一列，从第四行开始
                // 渲染数据
                List<PcbaDeviceParamType> pcbaDeviceParamTypeList = pcbaDeviceParamTypeDao.getPcbaDeviceParamTypeByPcbaDeviceTypeId(pcbaDeviceType.getPcbaDeviceTypeId(), null);
                if (pcbaDeviceParamTypeList != null && pcbaDeviceParamTypeList.size() > 0) {
                    for (int c = 0; c < pcbaDeviceParamTypeList.size(); c++) {
                        List<PcbaDeviceParam> pcbaDeviceParamList = pcbaDeviceParamDao.getAllPcbaDeviceParam(null, pcbaDeviceParamTypeList.get(c).getPcbaDeviceParamTypeId(), null);
                        if (pcbaDeviceParamList != null && pcbaDeviceParamList.size() > 0) {
                            for (int d = 0; d < pcbaDeviceParamList.size(); d++) {
                                index++;
                                Row row_ = sheet.createRow(index + 2);

                                // 序号
                                Cell cell_ = row_.createCell(0);
                                cell_.setCellValue(index);
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 设备
                                cell_ = row_.createCell(1);
                                cell_.setCellValue(pcbaDeviceType.getPcbaDeviceTypeNameCn());
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 项目大类
                                cell_ = row_.createCell(2);
                                cell_.setCellValue(pcbaDeviceParamTypeList.get(c).getPcbaDeviceParamTypeName());
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 设备能力评估项
                                cell_ = row_.createCell(3);
                                cell_.setCellValue(pcbaDeviceParamList.get(d).getPcbaDeviceParamNameCn());
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 设备加工参数
                                cell_ = row_.createCell(4);
                                cell_.setCellValue("");
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 设计说明
                                 /*1：普通文本
                                2.下拉选择
                                3：文件上传
                                4.下拉多选
                                11：数值类型[整数]
                                12：数值类型[小数]
                                21：百分比
                                31:不限制 or NA or 数字
                                */
                                cell_ = row_.createCell(5);
                                cell_.setCellValue(pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 1 ? "普通文本" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 2 ? "下拉选择" + "(" + pcbaDeviceParamList.get(d).getPcbaDeviceParamOptions() + ")" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 3 ? "文件上传" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 11 ? "整数" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 12 ? "小数" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 21 ? "百分比" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 4 ? "下拉多选" + "(" + pcbaDeviceParamList.get(d).getPcbaDeviceParamOptions() + ")" : (pcbaDeviceParamList.get(d).getPcbaDeviceParamFillType() == 31 ? "不限制 or NA or 数字" : ""))))))));
                                cell_.setCellStyle(bodyContextCellStyle);

                            }
                            // 合并第三列 【项目大类】
                            // System.out.println("pcbaDeviceParamList.size()=" + pcbaDeviceParamList.size());
                            if (pcbaDeviceParamList.size() > 1) {
                                if (index + 2 > beginIndex2) {
                                    sheet.addMergedRegion(new CellRangeAddress(beginIndex2, index + 2, 2, 2));
                                    beginIndex2 = index + 3;
                                }
                            } else {
                                beginIndex2 = index + 3;
                            }
                        }
                    }
                    // 合并第二列 【设备】
                    //System.out.println("beginRow===" + beginIndex1);
                    //System.out.println("lastRow===" + (index + 2));
                    //if(pcbaDeviceParamTypeList.size() > 1){
                    if (index + 2 > beginIndex1) {
                        sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index + 2, 1, 1));
                        beginIndex1 = index + 3;
                    }
                    /*}else{
                        beginIndex2 = index + 3;
                    }*/
                }

                String fileName = excelName + CommonUtils.getTimestamp() + ".xlsx";
                String pathPrefix = fileSaveUrl + "exportExcels\\";
                File folder = new File(pathPrefix);
                if (!folder.isDirectory()) {
                    folder.mkdirs();
                }
                String filePath = pathPrefix + fileName;
                // 导出Excel文件
                FileOutputStream outputStream = new FileOutputStream(filePath);
                workbook.write(outputStream);
                workbook.close();
                outputStream.close();

                byte[] data = null;
                InputStream in = new FileInputStream(filePath);
                data = new byte[in.available()];
                in.read(data);
                in.close();
                Base64.Encoder encoder = Base64.getEncoder();
                String base64 = encoder.encodeToString(data);

                Map<String, Object> resMap = new HashMap<>();
                resMap.put("base64", base64);
                resMap.put("fileName", fileName);
                return ResultUtil.success(resMap);
            } else {
                return ResultUtil.error(500, "未找到pcbaDeviceType", "Not found pcbaDeviceType", null);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result importPcbaDeviceParamExcelByDeviceType(Integer pcbaDeviceTypeId, MultipartFile file) {
        try {
            if (file == null) {
                return ResultUtil.error(500, "缺少参数file", "Miss Param file", null);
            }
            if (pcbaDeviceTypeId == null || "".equals(pcbaDeviceTypeId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaDeviceTypeId", "Miss Param pcbaDeviceTypeId", null);
            }
            // 1.得到一个输入流对象
            //FileInputStream in = FileConverterUtils.convertTo(file);
            InputStream inputStream = file.getInputStream();
            File f = FileConverterUtils.getTempFileFromInputStream(inputStream);
            // 2.将输入流对象进行解析 得到workbook对象
            //Workbook workbook = new XSSFWorkbook(in);
            Workbook workbook = WorkbookFactory.create(f);
            // 3.workbook中有几个工作簿
            int sheetNum = workbook.getNumberOfSheets();
            System.out.println("一共有" + sheetNum + "个工作簿");
            // 3.1通过workbook 创建工作簿对象
            //Sheet sheet1 = workbook.getSheetAt(0);
            //Sheet sheet2 = workbook.getSheetAt(1);
            Sheet sheet = workbook.getSheetAt(0);
            int allRows = sheet.getLastRowNum() + 1;
            String sheetName = sheet.getSheetName();
            System.out.println("当前sheetName：" + sheetName);
            List<Map<String, Object>> list2 = new ArrayList<>();
            //判断sheetName在不在设备列表里面
            Row row = sheet.getRow(2);
            String t1 = row.getCell(0) != null ? row.getCell(0).toString() : "";
            String t2 = row.getCell(1) != null ? row.getCell(1).toString() : "";
            String t3 = row.getCell(2) != null ? row.getCell(2).toString() : "";
            String t4 = row.getCell(3) != null ? row.getCell(3).toString() : "";
            String t5 = row.getCell(4) != null ? row.getCell(4).toString() : "";
            String t6 = row.getCell(5) != null ? row.getCell(5).toString() : "";
            if (t1.contains("序号") && t2.contains("设备") && t3.contains("项目大类") && t4.contains("设备能力评估项") && t5.contains("设备加工能力参数")) {
                // 表头符合的，循环获取每行数据
                for (int b = 3; b < allRows; b++) {
                    Map<String, Object> map2 = new HashMap<>();
                    Row rowV = sheet.getRow(b);
                    String v1 = rowV.getCell(1) != null ? rowV.getCell(1).toString() : "";
                    String v2 = rowV.getCell(2) != null ? rowV.getCell(2).toString() : "";
                    String v3 = rowV.getCell(3) != null ? rowV.getCell(3).toString() : "";
                    String v4 = rowV.getCell(4) != null ? rowV.getCell(4).toString() : "";

                    // 根据 v1，v2，v3 查询 key
                    PcbaDeviceType deviceType = pcbaDeviceTypeDao.getByName(v1);
                    if (deviceType != null) {
                        PcbaDeviceParamType byPcbaDeviceTypeIdAndName = pcbaDeviceParamTypeDao.getByPcbaDeviceTypeIdAndName(deviceType.getPcbaDeviceTypeId(), v2);
                        if (byPcbaDeviceTypeIdAndName != null) {
                            PcbaDeviceParam byNameAndPcbaDeviceParamTypeId = pcbaDeviceParamDao.getByNameAndPcbaDeviceParamTypeId(byPcbaDeviceTypeIdAndName.getPcbaDeviceParamTypeId(), v3);
                            if (byNameAndPcbaDeviceParamTypeId != null) {
                                String key = byNameAndPcbaDeviceParamTypeId.getPcbaDeviceParamKey();
                                Integer fillType = byNameAndPcbaDeviceParamTypeId.getPcbaDeviceParamFillType();
                                if (fillType != null && fillType == 2) {
                                    // 下拉，判断选项在不在里面
                                    String options = byNameAndPcbaDeviceParamTypeId.getPcbaDeviceParamOptions();
                                    if (options != null && options.length() > 0) {
                                        String[] arr = options.split(",");
                                        if (CommonUtils.arrContainsTarget(arr, v4)) {
                                            map2.put("key", key);
                                            map2.put("value", CommonUtils.removeZeros(v4));
                                        } else {
                                            map2.put("key", key);
                                            map2.put("value", "");
                                        }
                                    }
                                } else {
                                    map2.put("key", key);
                                    map2.put("value", CommonUtils.removeZeros(v4));
                                }
                            }
                        }
                    }
                    list2.add(map2);
                }
            } else {
                return ResultUtil.error(500, "模板错误", "Template Error", null);
            }
            return ResultUtil.success(list2);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getPcbaDeviceParamByKey(String pcbaDeviceParamKey) {
        try {
            if (pcbaDeviceParamKey == null || "".equals(pcbaDeviceParamKey)) {
                return ResultUtil.error(500, "缺少参数pcbaDeviceParamKey", "Miss Param pcbaDeviceParamKey", null);
            }
            return ResultUtil.success(pcbaDeviceParamDao.getPcbaDeviceParamByKey(pcbaDeviceParamKey));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }
}
